<template>
    <div>
        <!-- 分类切换 -->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl"
                class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <span :class="['mui-control-item',item.id === 0? 'mui-active':'']" v-for="item in cregtroy"
                        :key="item.id" @click="getPhotoByCategory(item.id)">
                        {{item.title}}
                    </span>
                </div>
            </div>

        </div>

        <!-- 图片列表 懒加载 -->
        <ul class="lazyul">
            <router-link v-for="item in photolist" :key="item.id" :to="'/home/photoinfo/'+item.id">
                <img v-lazy="item.img_url">
                <div class="imginfo">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-content">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>

    </div>
</template>

<script>
    import mui from '../../../lib/mui/js/mui.js'


    export default {
        data() {
            return {
                cregtroy: [],
                photolist: []
            }
        },
        created() {
            this.getPhotoCategory();
            this.getPhotoByCategory(0)
        },
        methods: {
            async getPhotoCategory() {
                const {
                    data
                } = await this.$http.get('/api/getimgcategory');
                if (data.status === 0) {
                    data.message.unshift({
                        title: '全部',
                        id: 0
                    });
                    this.cregtroy = data.message;
                }
            },
            async getPhotoByCategory(id) {
                const {
                    data
                } = await this.$http.get('/api/getimages/' + id);
                if (data.status === 0) return (this.photolist = data.message);
            }
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        }
    }
</script>

<style scoped>
    .mui-slider {
        touch-action: pan-x;
    }

    img[lazy=loading] {
        width: 40px;
        height: 300px;
        margin: auto;
    }

    .lazyul {
        margin: 0px;
        padding: 0px;
    }

    .lazyul a {
        list-style: none;
        margin-top: 10px;
        padding: 0px 5px;
        position: relative;
    }

    .lazyul a img {
        width: 100%;
        background-color: #ccc;
    }

    .imginfo {
        position: absolute;
        bottom: 0;
        color: #fff;
        background-color: rgba(0, 0, 0, 0.5);
        max-height: 100px;
        overflow: hidden;
    }

    .imginfo .info-title {
        font-size: 15px;
        text-align: center;
    }

    .imginfo .info-content {
        font-size: 14px;
        text-indent: 2em;
    }
</style>